package com.example.laserharp1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    TextView ipaddress, device;
    Button connection, function;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initialWork();              // ip & device in main page
        exqListener();              // jump to "connection" & "function"

    }

    private void initialWork(){
        connection = findViewById(R.id.connection);
        function = findViewById(R.id.function);
        ipaddress = (TextView) findViewById(R.id.ip);
        device = findViewById(R.id.device);

        if (GlobalVariable.ip!=null){
            ipaddress.setText("Target IP: " + GlobalVariable.ip);
        }else {
            ipaddress.setText("NONE");
        }

        if (GlobalVariable.device!=null){
            device.setText("Target Device: " + GlobalVariable.device);
        }else {
            device.setText("Not Connected");
        }
    }

    private void exqListener(){
        connection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ConnectionPage.class);
                startActivity(intent);
            }
        });
        function.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(MainActivity.this,FunctionPage.class);
                startActivity(intent);
            }
        });
    }
}
